"use strict";
cc._RF.push(module, '48792WNRgRKcry5/N52Ucu+', 'NPCKillerController');
// scripts/NPCKillerController.js

"use strict";

var e = require;
var t = module;
var n = i(e("RecorderPanel")),
    o = i(e("SoundMgr"));

function i(e) {
  return e && e.__esModule ? e : {
    "default": e
  };
}

window.NPCKillerController = {
  Instance: null
};
var a = e("LevelManager"),
    r = e("LevelSceneManager");
cc.Class({
  "extends": cc.Component,
  properties: {
    ControllerDiscoverFlag: 7,
    ControllerType: {
      type: cc.Enum(a.AvatarControllerType),
      "default": a.AvatarControllerType.BlackKiller
    },
    DefaultMHandAngle: 0,
    StayGameObject: cc.Node,
    ControllerAttackProgress: 0,
    ControllerAnimationBase: cc.Animation,
    ControllerAnimation: dragonBones.ArmatureDisplay,
    ControllerMHandRoot: cc.Node,
    AllowCurrentControllerMove: {
      type: Boolean,
      "default": !0
    },
    _ControllerAttackOperation: {
      type: Boolean,
      "default": !1
    },
    ControllerAttackOperation: {
      get: function get() {
        return this._ControllerAttackOperation;
      },
      set: function set(e) {
        this._ControllerAttackOperation = e;
      }
    },
    ControllerIsAttacked: {
      type: Boolean,
      "default": !1
    },
    ControllerHeadSprite: cc.Sprite,
    HeadLevelSpriteFrames: [cc.SpriteFrame],
    isJailed: {
      type: Boolean,
      "default": !1
    }
  },
  onLoad: function onLoad() {
    NPCKillerController.Instance = this;
  },
  start: function start() {
    this.ControllerMHandRoot && (this.DefaultMHandAngle = this.ControllerMHandRoot.angle);
    this.scheduleOnce(this.RandomKillerAnims, 2);
    this.ControllerAnimation && this.ControllerAnimation.addEventListener(dragonBones.EventObject.START, function () {
      if ("attacking" == this.ControllerAnimation.animationName) {
        cc.log("attack");
        this.AFUNC_KillColourBackground();
      }
    }.bind(this), this);
  },
  onDestroy: function onDestroy() {
    NPCKillerController.Instance = null;
  },
  update: function update(e) {
    if (!n["default"].GamePause) {
      var t;
      KingController.Instance && (t = this.node.position.sub(KingController.Instance.node.position).mag());

      if (this.ControllerAttackOperation) {
        if (!KingController.Instance) return;
        LevelManager.Instance.HealthProgressBar.progress >= .1 && t < LevelManager.Instance.AvatarControllerDistanceMinLimit && (this.ControllerAttackProgress += LevelManager.Instance.AttackProgressBarMoveSpeed * e);
      }

      var o = this.ControllerAttackProgress;

      if (this.ControllerAnimationBase) {
        this.ControllerHeadSprite && LevelManager.Instance.GameAllowOperation && null != this.HeadLevelSpriteFrames[0] && (o >= 0 && o < .35 ? this.ControllerHeadSprite.spriteFrame = this.HeadLevelSpriteFrames[0] : o >= .35 && o < .65 ? this.ControllerHeadSprite.spriteFrame = this.HeadLevelSpriteFrames[1] : o >= .65 && o <= 1 && (this.ControllerHeadSprite.spriteFrame = this.HeadLevelSpriteFrames[2]));
        if (this.ControllerMHandRoot) if (o <= 0) this.ControllerMHandRoot.angle = this.DefaultMHandAngle;else {
          if (!LevelManager.Instance.GameAllowOperation) return;
          o < 1 && (this.ControllerMHandRoot.angle += LevelManager.Instance.KillerAttackHandMoveSpeed);
        }
      }

      if (LevelManager.Instance.AllowAvatarControllerMove && this.AllowCurrentControllerMove) {
        if (!KingController.Instance) return;
        t >= LevelManager.Instance.AvatarControllerDistanceMinLimit ? this.node.x += LevelManager.Instance.AvatarControllerFastMoveSpeed * e : this.node.x += LevelManager.Instance.AvatarControllerMoveSpeed * e;
      }

      if (o >= 1) {
        o = 1;
        if (this.ControllerIsAttacked) return;
        this.ControllerIsAttacked = !0;
        this.ControllerAnimationBase ? this.ControllerAnimationBase.play("Attack") : this.ControllerAnimation.playAnimation("attacking", 1);
      }
    }
  },
  RandomKillerAnims: function RandomKillerAnims() {
    this.unschedule(this.RandomKillerAnimsCallback);
    this.RandomKillerAnimsCallback = this.scheduleOnce(function () {
      this.RandomKillerAnims();
    }, Math.round(Math.round(3 * Math.random() + 2)));

    if (!this.ControllerAttackOperation && !this.isJailed) {
      if (KingController.Instance && this.node.position.sub(KingController.Instance.node.position).mag() >= LevelManager.Instance.AvatarControllerDistanceMinLimit) return;
      this.ControllerAttackOperation = !0;
      this.ControllerAnimationBase || this.ControllerAnimation.playAnimation("attack", 1);
      o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[1]);
    }
  },
  onKingDiscoverFunction: function onKingDiscoverFunction() {
    switch (this.ControllerType) {
      case a.AvatarControllerType.RedDrinkSteward:
      case a.AvatarControllerType.GreenDrinkSteward:
      case a.AvatarControllerType.Clown:
      case a.AvatarControllerType.Woman:
      case a.AvatarControllerType.Girl:
      case a.AvatarControllerType.Dancer:
        this.DiscoverJail();
        return;
    }

    var e = Math.round(10 * Math.random());
    this.ControllerAttackOperation = !1;
    this.ControllerAttackProgress >= .45 && e >= this.ControllerDiscoverFlag ? this.DiscoverJail() : this.DiscoverStay();
  },
  onKingDiscoverFunctionOver: function onKingDiscoverFunctionOver() {
    LevelManager.Instance.GameCurrentOperationScene != a.GameSceneBlockType.Jail && (this.ControllerAnimationBase ? this.ControllerAnimationBase.play("Walk") : this.ControllerAnimation.playAnimation("walk", 0));
  },
  DiscoverJail: function DiscoverJail() {
    this.isJailed = !0;
    LevelManager.Instance.addLevel(1);
    LevelManager.Instance.SceneMainAudioSource.stop();
    LevelManager.Instance.GameCurrentOperationScene = a.GameSceneBlockType.Jail;
    LevelManager.Instance.AllowAvatarControllerMove = !1;
    LevelManager.Instance.GameAllowOperation = !1;
    LevelManager.Instance.CreateArmyController(this.node, this.ControllerType);
    o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[4]);
    this.ControllerAnimationBase ? this.ControllerAnimationBase.play("DiscoverJail") : this.ControllerAnimation.playAnimation("jail", 1);
    this.scheduleOnce(function () {
      o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[5]);
    }, 1);
    this.ControllerAttackProgress = 0;
  },
  DiscoverStay: function DiscoverStay() {
    if (LevelManager.Instance.GameCurrentOperationScene != a.GameSceneBlockType.Jail) {
      switch (this.ControllerType) {
        case a.AvatarControllerType.YellowKiller:
          o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[6]);
      }

      this.ControllerMHandRoot && (this.ControllerMHandRoot.angle = this.DefaultMHandAngle);
      this.ControllerAnimationBase ? this.ControllerAnimationBase.play("Stay") : this.ControllerAnimation.playAnimation("feign", 1);
      this.ControllerAttackOperation = !1;
      this.ControllerAttackProgress = 0;
    }
  },
  AFUNC_KillColourBackground: function AFUNC_KillColourBackground() {
    o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[9]);

    switch (this.ControllerType) {
      case a.AvatarControllerType.Woman:
      case a.AvatarControllerType.RedDrinkSteward:
      case a.AvatarControllerType.GreenDrinkSteward:
        ColourBackground.Instance.Show(cc.color(255, 255, 255));
        break;

      case a.AvatarControllerType.Master:
        ColourBackground.Instance.Show(cc.color(5, 200, 0));
        break;

      case a.AvatarControllerType.Girl:
        ColourBackground.Instance.Show(cc.color(255, 57, 210));
        break;

      default:
        ColourBackground.Instance.Show();
    }

    this.scheduleOnce(function () {
      switch (this.ControllerType) {
        case a.AvatarControllerType.Clown:
          KingController.Instance.Death(this.ControllerType, !0);
          this.ControllerAnimationBase.play("GetCrown");
          this.scheduleOnce(function () {
            ColourBackground.Instance.Show(cc.color(255, 255, 255));
          }, 1.8);
          this.scheduleOnce(function () {
            this.node.active = !1;
            LevelSceneManager.Instance.StartStoryScene(r.GameStorySceneType.WC);
          }, 2.3);
          break;

        case a.AvatarControllerType.Woman:
          this.node.active = !1;
          LevelSceneManager.Instance.StartStoryScene(r.GameStorySceneType.Love);
          break;

        case a.AvatarControllerType.RedDrinkSteward:
          KingController.Instance.DrinkRedWine();
          this.StayGameObject && (this.StayGameObject.active = !1);
          break;

        case a.AvatarControllerType.GreenDrinkSteward:
          KingController.Instance.DrinkGreenWine();
          this.StayGameObject && (this.StayGameObject.active = !1);
          break;

        case a.AvatarControllerType.Master:
          LevelManager.Instance.SceneMainAudioSource.stop();
          LevelManager.Instance.onGameOver(!1);
          var e = cc.instantiate(AssetManager.Instance.OtherPrefabs[0]);
          e.parent = LevelManager.Instance.SceneContentNode;
          e.position = KingController.Instance.node.position;
          this.ControllerAnimation.playAnimation("attacking", 1);
          KingController.Instance.node.destroy();
          LevelManager.Instance.GameAllowOperation = !1;
          LevelManager.Instance.AllowAvatarControllerMove = !1;
          break;

        case a.AvatarControllerType.Girl:
          this.ControllerAnimation.playAnimation("attacking", 1);
          LevelManager.Instance.GameAllowOperation = !1;
          this.scheduleOnce(function () {
            ColourBackground.Instance.Show(cc.color(0, 0, 0));
          }, 1);
          this.scheduleOnce(function () {
            LevelSceneManager.Instance.StartStoryScene(r.GameStorySceneType.BadKing_Girl);
          }, 1.5);
          break;

        case a.AvatarControllerType.Dancer:
          this.node.active = !1;
          LevelSceneManager.Instance.StartStoryScene(r.GameStorySceneType.Dancer);
          break;

        default:
          KingController.Instance.Death(this.ControllerType);
          var t = cc.instantiate(AssetManager.Instance.KingControllerPrefabs[this.ControllerType]);
          t.parent = LevelManager.Instance.SceneContentNode;
          t.position = KingController.Instance.node.position;
          var n = cc.instantiate(AssetManager.Instance.ControllerPrefabs[2]);
          n.parent = LevelManager.Instance.SceneContentNode;
          n.position = cc.v2(this.node.x - 700, this.node.y);
          this.node.destroy();
      }
    }, 1);
  }
});

cc._RF.pop();